(function (w) {
    //获取文本框内容并搜索
    let search_input = document.querySelector('#search_input');
    let search_button = document.querySelector('.search_button');
    search_button.addEventListener('click', function () {
        let search_key = search_input.value;//放在点击后触发
        search_input.value = '';
        if (search_key != '') {
            w.location.href = ('https://www.baidu.com/s?wd=' + search_key);
        }
    });
    //非激活状态下敲击enter，激活输入框
    document.addEventListener('keydown', function (e) {
        if (e.key === 'Enter') {
            search_input.focus();
        }
    });
    search_input.addEventListener('keydown', function (e) {
        if (e.key === 'Enter') {
            search_button.click();
        }
    })//添加enter回车搜索事件
})(window);